package com.szq.yygh.cmn.controller;

import com.szq.yygh.cmn.service.DictService;
import com.szq.yygh.common.result.Result;
import com.szq.yygh.hosp.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/***
 * All rights Reserved, Designed By www.jx-lab.com
 * @Title: DictController
 * @Description: 数据字典
 * @author lixy
 * @date 2021/8/19 8:52
 * @version V1.0
 * @Copyright: www.jx-lab.com Inc. All rights reserved.
 * 注意：本内容仅限于众合景轩信息技术有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
public class DictController {

    @Autowired
    private DictService dictService;

    @ApiOperation(value = "根据数据Id查询子数据列表")
    @GetMapping("/findChildData/{id}")
    public Result findChildData(@PathVariable Long id){
        List<Dict> result = dictService.findChildData(id);
        return Result.ok(result);
    }

    @ApiOperation(value = "导出数据字典")
    @GetMapping("/expertDictData")
    public void expertDictData(HttpServletResponse response){
        dictService.expertDictData(response);
    }

    @ApiOperation(value = "导入数据字典")
    @PostMapping("/importDictData")
    public Result importDictData(MultipartFile file){
        dictService.importDictData(file);
        return Result.ok();
    }

    @ApiOperation(value = "根据dictCode和value查询")
    @GetMapping("/getName/{dictCode}/{value}")
    public String getName(@PathVariable String dictCode, @PathVariable String value){
        String dictName = dictService.getDictName(dictCode, value);
        return dictName;
    }

    @ApiOperation(value = "根据value查询")
    @GetMapping("/getName/{value}")
    public String getName( @PathVariable String value){
        String dictName = dictService.getDictName(null, value);
        return dictName;
    }

    @ApiOperation(value = "根据dictCode查询下级节点")
    @GetMapping("/getByDictCode/{dictCode}")
    public Result getByDictCode(@PathVariable String dictCode){
        List<Dict> result = dictService.getByDictCode(dictCode);
        return Result.ok(result);
    }

}
